import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

public class HelicopterControlPanel extends JPanel implements ActionListener{

	// gui components
	JButton arrivalClearButton, arrivalMessageButton, departureClearButton,
			departureMessageButton;

	public HelicopterControlPanel() {

		// initialize the ui components
		initUI();
	}

	public void initUI() {
		// set the layout
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		// Create arrivals table
		JTable arrivalsTable = new JTable(new ArrivalsTableModel());
		arrivalsTable.setPreferredScrollableViewportSize(new Dimension(600, 60));

		// create arrivals scroll pane and add the arrivals table to it
		JScrollPane arrivalsScrollPane = new JScrollPane(arrivalsTable);

		// create arrivals actions panel
		JPanel arrivalsActionsPanel = new JPanel();
		arrivalClearButton = new JButton("Clear for Landing");
		arrivalClearButton.addActionListener(this);
		arrivalMessageButton = new JButton("Message Pilot");
		arrivalMessageButton.addActionListener(this);
		arrivalsActionsPanel.add(arrivalClearButton);
		arrivalsActionsPanel.add(arrivalMessageButton);

		// create arrivals panel and add the arrivals scroll pane and actions
		// panel to it
		JPanel arrivalsPanel = new JPanel();
		arrivalsPanel.setLayout(new BoxLayout(arrivalsPanel, BoxLayout.Y_AXIS));
		arrivalsPanel.setBorder(BorderFactory.createTitledBorder("Arrivals"));
		arrivalsPanel.add(arrivalsScrollPane);
		arrivalsPanel.add(arrivalsActionsPanel);

		// create departures table
		JTable departuresTable = new JTable(new DeparturesTableModel());
		departuresTable.setPreferredScrollableViewportSize(new Dimension(600, 60));

		// create departures scroll pane and add the departures table to it
		JScrollPane departuresScrollPane = new JScrollPane(departuresTable);

		// create departures actions panel
		JPanel departuresActionsPanel = new JPanel();
		departureClearButton = new JButton("Clear for Takeoff");
		departureClearButton.addActionListener(this);
		departureMessageButton = new JButton("Message Pilot");
		departureMessageButton.addActionListener(this);
		departuresActionsPanel.add(departureClearButton);
		departuresActionsPanel.add(departureMessageButton);

		// create departures panel and add the departures scroll pane and
		// actions panel to it
		JPanel departuresPanel = new JPanel();
		departuresPanel.setLayout(new BoxLayout(departuresPanel, BoxLayout.Y_AXIS));
		departuresPanel.setBorder(BorderFactory.createTitledBorder("Departures"));
		departuresPanel.add(departuresScrollPane);
		departuresPanel.add(departuresActionsPanel);

		// add the panels
		add(arrivalsPanel);
		add(departuresPanel);
		add(new RiskMitigationPanel());
	}

	// All table information goes in here.
	class ArrivalsTableModel extends AbstractTableModel {
		// Three different columns: User's name, position, and online status
		String[] columnNames = { "Identifier", "Orgin", "Location", "Status" };

		// Sample data. Data entered is a two dimensional array of objects.
		Object[][] data = { { "N35259", "LAX", "LAX PAD 7", "Docked" },
				{ "F23450", "PDX", "In Air", "Waiting for Landing" } };

		// Essential functions

		public int getColumnCount() {
			return columnNames.length;
		}

		public int getRowCount() {
			if (data == null)
				return 0;
			return data.length;
		}

		public String getColumnName(int col) {
			return columnNames[col];
		}

		// Returns the object at the indicated position
		public Object getValueAt(int row, int col) {
			if (data[row][col] == null)
				return null;
			return data[row][col];
		}

		// Turns booleans into checkboxes. Don't ask. I don't know how it works
		// myself.
		public Class getColumnClass(int c) {
			return getValueAt(0, c).getClass();
		}

		// The table cannot be edited by the user, no matter what.
		public boolean isCellEditable(int row, int col) {
			return false;
		}

		// Edits the value at the indicated position
		public void setValueAt(Object value, int row, int col) {
			data[row][col] = value;
		}
	}

	class DeparturesTableModel extends AbstractTableModel {
		// Three different columns: User's name, position, and online status
		String[] columnNames = { "Identifier", "Orgin", "Location", "Status" };

		// Sample data. Data entered is a two dimensional array of objects.
		Object[][] data = {
				{ "G32F34", "LAX", "LAX PAD 4", "Waiting for Takeoff" },
				{ "634N23", "PDX", "In Air", "Taking Off" } };

		// Essential functions

		public int getColumnCount() {
			return columnNames.length;
		}

		public int getRowCount() {
			if (data == null)
				return 0;
			return data.length;
		}

		public String getColumnName(int col) {
			return columnNames[col];
		}

		// Returns the object at the indicated position
		public Object getValueAt(int row, int col) {
			if (data[row][col] == null)
				return null;
			return data[row][col];
		}

		// Turns booleans into checkboxes. Don't ask. I don't know how it works
		// myself.
		public Class getColumnClass(int c) {
			return getValueAt(0, c).getClass();
		}

		// The table cannot be edited by the user, no matter what.
		public boolean isCellEditable(int row, int col) {
			return false;
		}

		// Edits the value at the indicated position
		public void setValueAt(Object value, int row, int col) {
			data[row][col] = value;
		}
	}

	public void actionPerformed(ActionEvent e) {
		// handle click events here
	}
}